# Maintainer: Johannes Schindelin <johannes.schindelin@gmx.de>

_realname=msmtp
pkgbase="mingw-w64-${_realname}"
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.6.2
tag=msmtp-${pkgver}
pkgrel=1
pkgdesc="An SMTP client (mingw-w64)"
arch=('any')
license=('GPL2+')
url="https://msmtp.sourceforge.io/"
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gettext"
         "${MINGW_PACKAGE_PREFIX}-gnutls"
         "${MINGW_PACKAGE_PREFIX}-gsasl"
         "${MINGW_PACKAGE_PREFIX}-libffi"
         "${MINGW_PACKAGE_PREFIX}-libidn"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread")
options=('strip')
source=(${_realname}::"git+https://git.code.sf.net/p/msmtp/code#tag=${tag}"
        '0001-include-winsock2.patch'
        '0002-dont-redefine-winver-constant.patch')
sha256sums=('SKIP'
            '3729fc8d9a11370324561a76cafe09035391e48c9a55876d1aaa5077944ebf8d'
            '0e8cf6e1b8975f2379437c416eff506dde69b26feaf41f91cf3eede32489b067')

prepare () {
  cd ${srcdir}/${_realname}

  patch -p1 -i "${srcdir}/0001-include-winsock2.patch"
  patch -p1 -i "${srcdir}/0002-dont-redefine-winver-constant.patch"
  autoreconf -i
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}
  ../${_realname}/configure --prefix=${MINGW_PREFIX}
  sed -i 's/-R\/mingw..\/lib//' src/Makefile
  touch ${srcdir}/${_realname}/src/*.c
  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install
}
